package com.ems.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ems.entity.TMaterial;
import com.ems.entity.vo.MyParam;
import com.ems.mapper.TMaterialMapper;
import com.ems.service.ITMaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZZH
 * @since 2022-06-27
 */
@Service
public class TMaterialServiceImpl extends ServiceImpl<TMaterialMapper, TMaterial> implements ITMaterialService {
    @Autowired
    TMaterialMapper tMaterialMapper;
    @Override
    public int addMaterial(TMaterial tMaterial) {
        return tMaterialMapper.insert(tMaterial);
    }

    @Override
    public int deleteMaterial(Integer id) {
        return tMaterialMapper.deleteById(id);
    }

    @Override
    public List<TMaterial> getList() {
        return tMaterialMapper.selectList(null);
    }

    @Override
    public int updateMaterial(TMaterial tMaterial) {
        return tMaterialMapper.updateById(tMaterial);
    }

    @Override
    public int scrapMaterial(Integer id) {
        return tMaterialMapper.scrapMaterial(id);
    }

    @Override
    public TMaterial selectByMatId(Integer id) {
        return tMaterialMapper.selectById(id);
    }

    @Override
    public int updateParam(MyParam param) {
        return tMaterialMapper.updateParam(param);
    }

    @Override
    @Transactional
    public List<TMaterial> selectByPage(int num, int count, String name, Integer state) {
        QueryWrapper<TMaterial> queryWrapper = new QueryWrapper<>();
        queryWrapper.
                like("name",name)
                .eq("state",state);
        Page<TMaterial> tMaterialPage = tMaterialMapper.selectPage(new Page<>(num, count), queryWrapper);
        List<TMaterial> list = tMaterialPage.getRecords();
        return list;
    }

    @Override
    public List<TMaterial> getDetail() {
        return tMaterialMapper.getDetail();
    }
}
